package concordia.comp6231.model;

public class Customer implements Comparable<Customer> {
	
	/**
	 * customerID is a unique identifier for a {@link Customer} instance
	 * customerID is a 6 digits
	 */
	private String customerID;
	private final int MIN_CUSTOMER_ID = 000000;
	private final int MAX_CUSTOMER_ID = 999999;
	
	public Customer(String customerID) {
		try {
			int intCustomerID = Integer.parseInt(customerID);
			if (intCustomerID < MIN_CUSTOMER_ID || intCustomerID > MAX_CUSTOMER_ID) {
				throw new IllegalArgumentException("Value should be between: " + MIN_CUSTOMER_ID + " and "+ MAX_CUSTOMER_ID);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		this.customerID = customerID;
	}
	
	public String getCustomerID() {
		return customerID;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Customer) {
			return ((Customer) obj).getCustomerID() == this.getCustomerID();
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return customerID.hashCode();
	}

	@Override
	public int compareTo(Customer o) {
		if (o != null) {
			return getCustomerID().compareTo(o.getCustomerID()); 
		} else {
			return -1;
		}
	}

}
